﻿using Factory.Customers.DTO;
using Factory.MesEntity.CustomerDatas;
using Factory.WarehouseManagement.SNDatas;
using Factory.WarehouseManagement.SNDatas.DTO;
using Microsoft.AspNetCore.Mvc;

namespace Factory.Web.Controllers.WarehouseManagement
{
    public class WarehouseController : Controller
    {

        ISNDataAppService _snDataAppService;

        public WarehouseController(ISNDataAppService snDataAppService)
        {
            _snDataAppService = snDataAppService;
        }
        public IActionResult WarehouseIndex()
        {
            return View();
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="customerName"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetSNDataList(string? snName, int page, int limit)
        {
            var (nuits, res) = _snDataAppService.GetSNDataList(snName, page, limit);
            return Json(new { data = nuits, code = 0, total = res });
        }

        public IActionResult WarehouseAddIndex()
        {
            return View();
        }



        [HttpPost]
        public JsonResult AddSNData(SNData sndata)
        {
            var res = _snDataAppService.CreateAsync(sndata);
            return Json(new { code = res, msg = "添加成功" });
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns>返回对应数据</returns>
        [HttpPost]
        public JsonResult SNDataDelete(int id)
        {
            var res = _snDataAppService.DeleteAsync(id);
            return Json(new { code = res, msg = "删除成功" });
        }

        /// <summary>
        /// 获取页面
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateCustomerDatatView(int id)
        {
            ViewBag.Id = id;
            return View();
        }

        [HttpGet]
        /// <summary>
        /// 获取客户数据详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetSNDataById(int id)
        {
            var customer = _snDataAppService.GetSNDataById(id);
            return Json(new { code = 0, data = customer });
        }
        [HttpPost]
        /// <summary>
        /// 更新客户数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public JsonResult UpdateAsync(SNDataUpdateDto input)
        {

            var customer = _snDataAppService.UpdateAsync(input);

            return Json(new { code = 0, data = customer });
        }

    }
}
